package com.fram.controller.api.android;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseController;
import com.fram.entity.UserVirtualWallet;
import com.fram.entity.UserWithdrawCardNumber;
import com.fram.service.api.v1.android.WalletAndroidService;

@RestController
@RequestMapping("/api/{version}/app/manage/wallet")
public class WalletAndroidController extends BaseController{
	
	private static Logger LOG = LoggerFactory.getLogger(WalletAndroidController.class);
	
	@Autowired
	private WalletAndroidService walletAndroidService;
	
	//修改密码  
	@ApiVersion(1.0)
	@RequestMapping("add/pwd")
	private ResponseMsg addPwd(@RequestBody UserVirtualWallet request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.setUserId(getApiUserId());
			walletAndroidService.addPwd(request);
		} catch (ProException e) {
			LOG.error("-添加支付密码出错-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--添加支付密码异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	//展示可提现金额 //展示钱包
	@ApiVersion(1.0)
	@RequestMapping("balance")
	private ResponseMsg balance() {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(walletAndroidService.exhibition(getApiUserId()));
		} catch (ProException e) {
			LOG.error("-账户余额出错-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--账户余额异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	//
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody PageBean<UserWithdrawCardNumber> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.getParam().setUserId(getApiUserId());
			msg.setData(walletAndroidService.list(request));
		} catch (ProException e) {
			LOG.error("-账户卡列表出错-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--账户卡列表异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	//
	@ApiVersion(1.0)
	@RequestMapping("add")
	private ResponseMsg add(@RequestBody UserWithdrawCardNumber request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.setUserId(getApiUserId());
			walletAndroidService.add(request);
		} catch (ProException e) {
			LOG.error("-增加账户卡错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--增加账户卡异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("detail")
	private ResponseMsg detail(Long id) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(walletAndroidService.detail(id));
		} catch (ProException e) {
			LOG.error("-账户卡详情错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--账户卡详情异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("update")
	private ResponseMsg update() {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("delete")
	private ResponseMsg delete(Long id) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			walletAndroidService.delete(id);
		} catch (ProException e) {
			LOG.error("-删除银行卡错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--删除银行卡异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
